<template>
    <div class="tooler-list-emb" :class="{ excess: isExcess }">

        <DesignerEmbPlatenName :name="platenActive.name"  />,
        <span v-if="!isExcess" style="margin-left: 10px;">{{ activeLayer.stitches_count }} stitches,</span>


        <UxPopper placement="bottom">

            <span v-if="isExcess">{{ activeLayer.stitches_count }} stitches,</span>
            <CommonCurrencyRate :price="activeLayer.price" type="unit|price" />

            <blockquote slot="pop">
                <table>
                    <thead>
                        <tr>
                            <th></th>
                            <th>Stitches</th>
                            <th>Price</th>
                        </tr>
                    </thead>
                    <tbody>
                        <!-- <tr>
                            <td>Total stitches</td>
                            <td>{{activeLayer.stitches_count}}</td>
                            <td>
                                <CommonCurrencyRate :price="activeLayer.price" type="price" />
                            </td>
                        </tr> -->
                        <tr>
                            <td>
                                <DesignerEmbPlatenName :name="platenActive.name" />
                                Frame ({{platenActive.base_stitches}} stitches included)
                            </td>
                            <td v-if="platenExceeded.stitches_count">{{ platenActive.base_stitches }}</td>
                            <td v-else>{{ activeLayer.stitches_count }}</td>
                            <td>
                                <CommonCurrencyRate :price="platenActive.base_price" type="price" />
                            </td>
                        </tr>
                        <tr>
                            <td>Extra stitches (1000 stitches / USD 0.3)</td>
                            <td>{{ platenExceeded.stitches_count }}</td>
                            <td>
                                <CommonCurrencyRate :price="platenExceeded.price" type="price" />
                            </td>
                        </tr>
                    </tbody>
                </table>
                <p>
                    <span v-if="isExcess">The maximum stitches for this frame is {{platenActive.max_stitches}}. </span>
                    <a href="/document/help-center?classify=10&detail=196" target="_blank">How is Embroidery Pricing Calculated?</a>
                </p>
            </blockquote>

        </UxPopper>

    </div>
</template>

<script>
import { mapGetters, mapState } from "vuex";
export default {
    props: {
        activeLayer: { type: Object, default: () => ({}) }
    },
    computed: {
        ...mapGetters("designer", {
            platens: "getPlatens",
        }),

        platenActive () {
            const layer = this.activeLayer || {}
            return this.platens.find(i => i.code == layer.platens_id) || {}
        },

        // 超过的
        platenExceeded () {

            if (this.activeLayer.stitches_count > this.platenActive.base_stitches) {
                // 超过了
                const exceeded = this.activeLayer.stitches_count - this.platenActive.base_stitches
                return {
                    stitches_count: exceeded,
                    price: Math.ceil(exceeded / 1000) * 30
                }
            } else {
                return { stitches_count: 0, price: 0 }
            }
        },

        // 超出限制
        isExcess () {
            return this.activeLayer.stitches_count > this.platenActive.max_stitches
        }

    },

};
</script>
<style lang="scss" scoped>
.tooler-list-emb {
    padding-top: 16px;
    padding-bottom: 4px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: Roboto, Roboto;
    font-weight: 400;
    font-size: 14px;
    color: #292929;
    position: relative;
    z-index: 1;





    .popper::v-deep {
        margin-left: 10px;

        .popper-name {
            line-height: 16px;
            cursor: pointer;
            height: 16px;
            font-weight: 400;
            font-size: 14px;
            color: #292929;
            box-sizing: border-box;
            border-bottom: 1px solid #555555;

            .currency-rate {
                font-size: 14px;
            }

            &:hover {
                border-bottom-color: transparent;
            }

        }

        .popper-content {
            box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.11);
            border-radius: 8px;
            border: 1px solid #e0e0e0;
            margin-left: -40px !important;

            &>i {
                display: none;
            }

        }

        &.visible .popper-name {
            border-bottom-color: transparent !important;
        }



    }

    blockquote {
        background: #ffffff;
        border-radius: 8px;
        overflow: hidden;
        margin: 0;
        width: 370px;

        table {
            width: 100%;

            th {
                background: #fafafa;
                font-family: Roboto-Medium, Roboto;
                font-weight: 500;
                font-size: 12px;
                line-height: 14px;
                color: #000000;
                padding: 10px 12px;
            }

            tbody td {
                font-family: Roboto, Roboto;
                font-weight: 400;
                font-size: 12px;
                color: #292929;
                line-height: 14px;
                padding: 10px;
                white-space: nowrap;
                border: 1px solid #e0e0e0;

                &:first-child {
                    font-family: Roboto-Medium, Roboto;
                    border-left: none;
                }

                &:last-child {
                    font-family: Roboto-Medium, Roboto;
                    border-right: none;
                }
            }
        }

        p {
            display: block;
            font-size: 12px;
            position: relative;
            padding: 9px 10px 10px 10px;
            font-family: Roboto, Roboto;
            font-weight: 400;
            font-size: 12px;
            color: #555555;
            line-height: 18px;

            span{
                display: block;
                color: #C62828;
            }

            &>a {
                color: #087196;
                cursor: pointer;
                text-decoration: underline;

                &:hover {
                    text-decoration: none;
                }
            }

            &>svg {
                width: 12px;
                height: 12px;
                position: absolute;
                left: 9px;
                top: 12px;
                color: #b8b8b8;
            }
        }
    }

    &.excess .popper::v-deep {
        .popper-name {
            color: #C62828;
            border-bottom: 1px solid #C62828;
        }
    }
}
</style>
